home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / redo / redoFileAddSlotted.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  8.7 KB  |  350 lines

  1. /*
  2.  *   $RCSfile: redoFileAddSlotted.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:58 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "log.h"
  57. #include "pool.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "trans.h"
  61. #include "bitmap.h"
  62. #include "file.h"
  63. #include "openlog.h"
  64. #include "bf_extfuncs.h"
  65. #include "bm_extfuncs.h"
  66. #include "fi_intfuncs.h"
  67. #include "trans_extfuncs.h"
  68. #include "redo_extfuncs.h"
  69. #include "logaction.h"
  70. #include "util_funcs.h"
  71. #include "thread_globals.h"
  72. #include "bf_globals.h"
  73. #include "log_globals.h"
  74. #include "log_extfuncs.h"
  75.  
  76.  
  77. /*
  78.  *    This function redoes the setting of the file root page pointers
  79.  *    to the first and last logical pages in the file, and the 
  80.  *    setting of the nextLogicalPid field of the last page in the
  81.  *    file
  82.  */
  83.  
  84.  void
  85. redoFileAddSlotted (
  86.  
  87.     LOGRECORDHDR        *record 
  88. )
  89. {
  90.  
  91.     PID                *rootPID;
  92.     PID                lastPID;
  93.     SHORTPID        newPage;
  94.     NODEPAGE        *nodePage;
  95.     SLOTTEDPAGE        *slottedPage;
  96.     GROUPLINK        *groupLink;
  97.     BOOL            firstPage;
  98.     DIRTYPAGEINFO    *dirtyInfo;
  99.     LRC                *lrc;
  100.  
  101.  
  102.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN.offset));
  103.  
  104.     /*
  105.      *    get a pointer to the file root page id
  106.      *    get flag for whether this is the first page in the file
  107.      *    get pid of new page added to file
  108.      */
  109.     rootPID = &(record->actionPid);
  110.     firstPage = *(BOOL*) GET_LOG_IMAGE(record, 0);
  111.     newPage = *(SHORTPID*) GET_LOG_IMAGE(record, 1);
  112.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("file root page:%d", rootPID->page));
  113.  
  114.     /*
  115.      *    check to see if the root page is in the dirty page list
  116.      */
  117.     if ((dirtyInfo = searchDirtyPageTable(rootPID)) == NULL)    {
  118.  
  119.         /*
  120.          *    don't need to redo
  121.          */
  122.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  123.         goto handle_page_link;
  124.     }
  125.  
  126.     /*
  127.      *  check to see if the lrc on the page is greater than
  128.      *  the lrc in the log record.
  129.      *  Also check the lsn for the case of pages which never made it
  130.      *  back from the client.
  131.      */
  132.     if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
  133.  
  134.         /*
  135.          *  don't need to redo
  136.          */
  137.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  138.         return;
  139.     }
  140.  
  141.     /*
  142.      * Read in first page of file and grab node type
  143.      */
  144.     if ((groupLink = bf_ReadPage(UserBufGroup, rootPID, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
  145.  
  146.         SM_ERROR(TYPE_FATAL, Active->errno);
  147.     }
  148.  
  149.     /*
  150.      *    get a pointer to the node page
  151.      */
  152.     nodePage = (NODEPAGE *) groupLink->bufFrame;
  153.  
  154.     /*
  155.      *    check to see if the lrc on the page is greater than
  156.      *    the lrc in the log record
  157.      */
  158.     if (compareLRC( &(record->actionLRC), &(nodePage->header.lrc)) <= 0)    {
  159.  
  160.         /*
  161.          *    don't need to redo
  162.          *    mark the page lrc
  163.          */
  164.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  165.         dirtyInfo->lrc = nodePage->header.lrc;
  166.  
  167.         /*
  168.          *    release the page
  169.          */
  170.         signalSemaphore( &(groupLink->pageHash->semaphore) );
  171.         bf_UnfixPage(groupLink, BF_DEFAULT, FALSE);
  172.         goto handle_page_link;
  173.     }
  174.  
  175.     /*
  176.      *    See if this is the first page added and then update the
  177.      *    proper pointers
  178.      */
  179.     if (firstPage) {
  180.         
  181.         /*
  182.          *    Update the first and the last
  183.          */
  184.         SM_ASSERT(LEVEL_3, nodePage->header.firstLogicalNode == NULLPID && nodePage->header.lastLogicalNode == NULLPID);
  185.         nodePage->header.firstLogicalNode = newPage;
  186.         nodePage->header.lastLogicalNode = newPage;
  187.  
  188.     } else {
  189.  
  190.         /*
  191.          *    Update the only the last
  192.          */
  193.         SM_ASSERT(LEVEL_3, nodePage->header.firstLogicalNode != NULLPID && nodePage->header.lastLogicalNode != NULLPID);
  194.         nodePage->header.lastLogicalNode = newPage;
  195.     }
  196.  
  197.     /*
  198.      *    mark the LRC on the page
  199.      *    Set up the firstLSN/LRC for the page
  200.      */
  201.     nodePage->header.lrc = record->actionLRC;
  202.     DEPEND_LOG(groupLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  203.     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d", nodePage->header.lrc.count));
  204.  
  205.     /*
  206.      *    release  the page semaphore
  207.      */
  208.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  209.  
  210.     /*
  211.      *    release and dirty the page
  212.      */
  213.     bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
  214.  
  215.  
  216. /* 
  217.  *    Update link on last page in the file 
  218.  */
  219. handle_page_link:  
  220.  
  221.     /*
  222.      *    If this is not the first page, then update the link on the
  223.      *    last page
  224.      */
  225.     if (!firstPage) {
  226.  
  227.         /*
  228.          *    Get a pointer to the last slotted page in the file
  229.          *    and a pointer to the log record lrc for this page
  230.          */
  231.         SM_ASSERT(LEVEL_3, 2*sizeof(SHORTPID) == GET_LOG_IMAGE_SIZE(record, 1));
  232.         /* get second pid in image 1 */
  233.         lastPID.page = *(((SHORTPID*) GET_LOG_IMAGE(record, 1))+1);
  234.         lastPID.volid = rootPID->volid;
  235.         lrc = (LRC*) GET_LOG_IMAGE(record, 2);
  236.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("last slotted page:%d", lastPID.page));
  237.  
  238.         /*
  239.          *    check to see if the last page is in the dirty page list
  240.          */
  241.         if ((dirtyInfo = searchDirtyPageTable(&lastPID)) == NULL)    {
  242.  
  243.             /*
  244.              *    don't need to redo
  245.              */
  246.             TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  247.             return;
  248.         }
  249.  
  250. #ifdef INIT_LRC_IS_LSN
  251.  
  252.         /*
  253.          *    If the init dirty LRC is the end-of-log lsn, then the
  254.          *    operation must be redone since there is no guarantee 
  255.          *    as to how the LRCs will compare.
  256.          */
  257.  
  258. #else
  259.         /*
  260.          *  check to see if the lrc on the page is greater than
  261.          *  the lrc in the log record
  262.          */
  263.         if (compareLRC( lrc, &(dirtyInfo->lrc) ) < 0)  {
  264.  
  265.             /*
  266.              *  don't need to redo
  267.              */
  268.             TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  269.             return;
  270.         }
  271.  
  272.         /*
  273.          *  Make sure the comparison was correct
  274.          */
  275.         SM_ASSERT(LEVEL_3, compareLSN( &(record->recordLSN), &(dirtyInfo->lsn)) >= 0);
  276.  
  277. #endif /* INIT_LRC_IS_LSN */
  278.  
  279.         /*
  280.          * Read in last page of file
  281.          */
  282.         if ((groupLink = bf_ReadPage(UserBufGroup, &lastPID, SLOTTED_PAGE2SIZE, BF_SEM)) == NULL) {
  283.  
  284.             SM_ERROR(TYPE_FATAL, Active->errno);
  285.         }
  286.  
  287.         /*
  288.          *    get a pointer to the node page
  289.          */
  290.         slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  291.  
  292. #ifdef INIT_LRC_IS_LSN
  293.  
  294.         /*
  295.          *    If the init dirty LRC is the end-of-log lsn, then the
  296.          *    operation must be redone since there is no guarantee 
  297.          *    as to how the LRCs will compare.
  298.          */
  299.  
  300. #else
  301.         /*
  302.          *    check to see if the lrc on the page is greater than
  303.          *    the lrc in the log record.  Note that the comparison is 
  304.          *    < not <= since the lrc was not incremented upon the
  305.          *    generation of this log record.
  306.          */
  307.         if (compareLRC( lrc, &(slottedPage->header.lrc)) < 0)    {
  308.  
  309.             /*
  310.              *    don't need to redo
  311.              *    mark the page lrc
  312.              */
  313.             TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  314.             dirtyInfo->lrc = nodePage->header.lrc;
  315.  
  316.             /*
  317.              *    release the page
  318.              */
  319.             signalSemaphore( &(groupLink->pageHash->semaphore) );
  320.             bf_UnfixPage(groupLink, BF_DEFAULT, FALSE);
  321.             return;
  322.         }
  323.  
  324. #endif /* INIT_LRC_IS_LSN */
  325.  
  326.         /*
  327.          *    Redo the link update
  328.          */
  329.         slottedPage->header.nextLogicalPid = newPage;
  330.  
  331.         /*
  332.          *    do not mark the LRC on the page
  333.          *    Set up the firstLSN/LRC for the page
  334.          */
  335.         /*slottedPage->header.lrc = *lrc;*/
  336.         DEPEND_LOG(groupLink->pageHash, 0, &(record->recordLSN), lrc);
  337.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d", slottedPage->header.lrc.count));
  338.  
  339.         /*
  340.          *    release  the page semaphore
  341.          */
  342.         signalSemaphore( &(groupLink->pageHash->semaphore) );
  343.  
  344.         /*
  345.          *    release and dirty the page
  346.          */
  347.         bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
  348.     }
  349. }
  350.